package cn.wyd.shield.http.support;

import java.io.Serializable;
import java.util.regex.Pattern;

public class Url implements Serializable {
    private String url;
    private String method;
    private Boolean authentication;
    private String role;
    private String permissions;
    private Pattern pattern;


    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getPermissions() {
        return permissions;
    }

    public void setPermissions(String permissions) {
        this.permissions = permissions;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
        setPattern(Pattern.compile(url.replaceAll("\\*","\\.*")));
    }

    public Boolean getAuthentication() {
        return authentication;
    }

    public void setAuthentication(Boolean authentication) {
        this.authentication = authentication;
    }
    public Pattern getPattern() {
        return pattern;
    }

    public void setPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    public Url(String url, Boolean authentication) {
        setUrl(url);
        this.authentication = authentication;
    }

    public Url(String url, String method, Boolean authentication) {
        setUrl(url);
        this.method = method.toLowerCase();
        this.authentication = authentication;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Url{");
        sb.append("url='").append(url).append('\'');
        sb.append(", method='").append(method).append('\'');
        sb.append(", authentication=").append(authentication);
        sb.append(", role='").append(role).append('\'');
        sb.append(", permissions='").append(permissions).append('\'');
        sb.append(", pattern=").append(pattern);
        sb.append('}');
        return sb.toString();
    }
}
